#include "dyn_functor_maps1d_logisticMap.h"

LogisticMap::LogisticMap(const double parameter, const int p)
    : Maps1D(p)
{
    setParameter(parameter);
}

double LogisticMap::iterate(double x, const int p)
{
    if (p==0)
        return x;

    for (int i=0;i<p;i++)
    {
        x = r*x*(1.0-x);
    }
    return x;
}

double LogisticMap::jacobian(const double x, const int p)
{
    // We prepare a vector of size p
    // and sets its initial value.
    arma::vec jacVec(p);
    jacVec(0) = x;

    // We store the values of the jacobian
    // at different iterates in the vector.
    for (int i=1;i<p;i++)
    {
        jacVec(i) = iterate(jacVec(i-1),1);
    }

    for (int i=0;i<p;i++)
    {
        jacVec(i)=r*(1-2*jacVec(i));
    }

    // The jacobian is the product of all
    // elements of the vector.
    return arma::prod(jacVec);
}
